(function ($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
})(jQuery);
$(function () {
    $("#submit").click(function () {
        $.ajax({
            type:"POST",
            url:"/book/replaceBackgroup",
            data:{
                "file":$("#pic").val()
            },
            dataType:"json",
            success:function (data) {
                alert(data)
            },complete:function(){
                alert("替换成功,项目重启后生效")
            }
        }
        );
    })
    $("#shezhi").click(function () {
        $("#j_setting").attr("style","display: block;");
    })
    $("#guanbi").click(function () {
        $("#j_setting").attr("style","display: none;");
    })
    $.ajax({
        type: "POST",
        url: "/cartoon/getCartoonChapter",
        data: {
            "cartoonCod": $.getUrlParam('cartoonCod'),
            "chapterCod": $.getUrlParam('chapterCod')
        },
        dataType: "json",
        success: function (data) {
            for (let i = 0; i < data.catalogueSrc.length; i++) {
                $("#body").append("<img class='imgs' src='" + data.catalogueSrc[i] + "'/>");
            }
            $("#head").append(data.catalogueName);
            if (data.upCode != null) {
                $("#j_chapterPrev").attr("href", "readCartoon.html?cartoonCod=" + $.getUrlParam('cartoonCod') + "&&chapterCod=" + data.upCode);
            }
            $(".back").attr("href", "CartoonCatalogue.html?cartoonCod=" + $.getUrlParam('cartoonCod'))
            if (data.nextCode != null) {
                $("#j_chapterNext").attr("href", "readCartoon.html?cartoonCod=" + $.getUrlParam('cartoonCod') + "&&chapterCod=" + data.nextCode);
            }
        },
        complete: function (data) {

        }
    });

    function getPath(obj) {
        if (obj) {
            if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
                obj.select();
                return document.selection.createRange().text;
            } else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
                if (obj.files) {
                    return obj.files.item(0).getAsDataURL();
                }
                return obj.value;
            }
            return obj.value;
        }
    }
})

